<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
            <title>Cindy JS</title>
            <script type="text/javascript" src="../build/js/Cindy.js"></script>
            </head>

	<body style="font-family:Arial;">

        <h1>Linear Algebra Tests</h1>
<div  style="width:800px; line-height: 1.5">
</div>
        <script id='init' type='text/x-cindyscript'>
        </script>

        <script id='csmove' type='text/x-cindyscript'>
//magic = [[8, 1,6], [3,5,7], [4,7,2]];
test1 = [[4,-1,-2,2], [1,2,0,1],[-2,0,3,-2], [2, 1, -2, -1]];
test2 = [[0,2, -1], [2, -1, 1], [2, -1, 3]];
//AA = [[12, -51, 4], [6, 167, -68], [-4, 24, -41]];
//AA = [	[-7, 13+random(), -16],
//	[13, -10, 13],
//	[5, -13, 7+random()]];
//AA =   [[0,   1,   6, random()],
//   	[3,   5,   7, random()],
//   	[2,   0,   1, random()],
//   	[random(),   9,   2, random()]];


rrand = random();
//println(rrand);
AA =   [[5,   1,   random(), 1],
   	[random(),   5,   7, 6],
   	[0,   0,   5, 5],
   	[random(),   0,   0, rrand]];

//AA = transpose(AA);

//AA = [[0,0,0], [0,0,0], [0,0,1]];

//AA = [[1, 1, 6, 0.7060750259552151], [3, 5, 7, 0.5834713182412088], [2, 0, 1, 0.07858391688205302], [0.007754674414172769, 9, 2, 0.780535752652213]];

//AA = [[1, 1,0], [0,1,0], [0,0,1]];

//AA = [	[1, 1,0],
//	[0, 3, 1],
//	[0, 0, 2]];
//println(magic);
//eig(magic);
//println(AA);
[val,vec] = eig(AA);
vec = transpose(vec);
tt1 = |AA*vec_1 - vec_1*val_1|;
tt2 = |AA*vec_2 - vec_2*val_2|;
tt3 = |AA*vec_3 - vec_3*val_3|;
tt4 = |AA*vec_4 - vec_4*val_4|;
println(tt1);
println(tt2);
println(tt3);
println(tt4);
//        n = 100;
//        AA=zeromatrix(n,n);
//       repeat(n,j,
//         repeat(n,k,
//           AA_j_k=(random()) + i*(random());
//         );
//       );
//
//
//        bb = zerovector(n);
//        repeat(n,j, bb_j = random() + i*(random()));
//
//        javascript("var tt; t = Date.now()");
//        x = linearsolve(AA,bb);
//	println("time for linearsolve");
//        javascript("console.log(Date.now()-t)");
//	drawtext((-6,6), "linearsolve, inverse and det: x=linearsolve(A,b), x=inv(A)*b, det(A) == LUdet(A)");
//        drawtext((-6, 5),"|A*x-b|");
//        drawtext((-3, 5),|AA*x-bb|);
// //       println(|AA*x-bb| < 0.0000001);
//        javascript("var tt; t = Date.now()");
//	invA = inverse(AA);
//	println("time for inverse");
//        javascript("console.log(Date.now()-t)");
//        drawtext((-6, 4),"|A^-1*b-x|");
//        drawtext((-3, 4),|invA*bb-x|);
////        println(|(invA*bb)-x|);
////        println(|(inverse(AA)*bb)-x| < 0.0000001);
//
//       repeat(n,j,
//         repeat(n,k,
//           if(j<k,AA_j_k=0,AA_j_k = AA_j_k +0.25+0.25*i);
//         );
//       );
//
//	mydet = 1;
//	repeat(n, j, mydet = mydet*AA_j_j);
//	//println("mydet" +  mydet);
//        javascript("var tt; t = Date.now()");
//	println("time for det");
//	ludet = det(AA);
//        javascript("console.log(Date.now()-t)");
////	println("ludet" + ludet);
//        drawtext((-6, 3),"|manual det - LUdet|");
//        drawtext((-1, 3),|mydet - ludet|);
//
//        drawtext((-6, 2),"LUdet");
//        drawtext((-1, 2),ludet);


AA =   [[5,   1,   7, 1],
   	[5,   1,   7, 1.00001],
   	[0,   0,   5, 5],
   	[random(),   0,   0, rrand]];
println(rank(AA, precision-> 0.0001));

println(kernel(AA), precision-> 0.0001);
println(|AA*transpose(kernel(AA))_1|)


        </script>



        <div style="position:relative">
        <div  id="CSCanvas" style="width:800px; height:500px; border:2px solid #000000; top:0px; left:0px;"></div>
</div>

        <script type="text/javascript">

            var gslp=[
//                      {name:"O", type:"Free", pos:[0,0],color:[0,0,0],pinned:true,size:3},
//                      {name:"B", type:"Free", pos:[9,1],color:[1,0,0],size:0.01},
//                      {name:"C", type:"Free", pos:[-6,6],color:[1,0,0],size:0.01},
//		      {name:"bc", type:"Join", args:["B","C"],color:[0,0,1]},
//                      {name:"D", type:"PointOnLine", pos:[1,2],args:["bc"],color:[1,0,0],size:3},




                    ];
                     CindyJS({canvasname:"CSCanvas",
                        movescript:"csmove",
                        initscript:"init",
                        geometry:gslp,
 //                       grid:1,
//                        snap:true,
                        transform:[{scale:1.5},{translate:[0,0]}],
}
                        );

        </script>
<div  style="width:800px; line-height: 1.5">

</div>
<br>
<br>




	</body>
</html>
